<?php

require_once ROOT_APPLICATION_MODULES_TEMPLATE_FORMS.DS."MultimediaFileSetAssoc.php";
require_once ROOT_APPLICATION_MODULES_TEMPLATE_OBJECTS.DS."MultimediaFileSetAssoc.php";
require_once ROOT_APPLICATION_MODULES_TEMPLATE_MODELS.DS."MultimediaFileSetAssocs.php";

class IndexController extends Zend_Controller_Action
{
	
    public function init()
    {
        /* Initialize action controller here */
    }
    
    public function addAction()
    {   
    	//Create form enter info for new Page
    	$form = new Application_Form_MultimediaFileSetAssoc();
    	
    	//Set label for the button
        $form->submit->setLabel('Add');
        
        //Set client view page form  = $form
        $this->view->form = $form;
        
        //If can get client request 
        if ($this->getRequest()->isPost()) 
        {
        	//Get data from form.
            $formData = $this->getRequest()->getPost();
            if ($form->isValid($formData))   //If data is valid 
            {
            	//Get data one by one
                $file_id = (int)$form->getValue('file_id');
                $set_id = (int)$form->getValue('set_id');                
                
                //Create new Core Page object from datas
                $MultimediaFileSetAssoc = new MultimediaFileSetAssoc(null, $file_id, $set_id);
                
                //Create Core Page model 
                $MultimediaFileSetAssocs = new End_Models_MultimediaFileSetAssocs();
                
                //Use insert function from Core Page model
                $MultimediaFileSetAssocs->_insert($MultimediaFileSetAssoc);
                
                //Move to index page
                $this->_helper->redirector('index');
            } else 
            {
            	//Return form
                $form->populate($formData);
            }
        }
    }
    
    public function deleteAction()
    {	
    	if ($this->getRequest()->isPost()) 
    	{
            $del = $this->getRequest()->getPost('del'); 
    		if ($del == 'Yes') 
            {
                $id = (int)$this->getRequest()->getPost('id');
                $MultimediaFileSetAssocs = new End_Models_MultimediaFileSetAssocs();
                $MultimediaFileSetAssocs->_delete($id);
            }
            $this->_helper->redirector('index');
        } else 
        {
            $id = $this->_getParam('id', 0);
            $MultimediaFileSetAssocs = new End_Models_MultimediaFileSetAssocs();
            $this->view->page = Utility_Converter::objectToArray($MultimediaFileSetAssocs->_find($id));
        }
    }
    
    public function editAction()
    {
    	$form = new Application_Form_MultimediaFileSetAssoc();
        $form->submit->setLabel('Save');
        $this->view->form = $form;
       
        if ($this->getRequest()->isPost()) 
        {
            $formData = $this->getRequest()->getPost();
            if ($form->isValid($formData)) 
            {
                $id = (int)$form->getValue('id');
				$file_id = (int)$form->getValue('file_id');
				$set_id = (int)$form->getValue('set_id');                
   				//lay thong tin
				$MultimediaFileSetAssoc = new MultimediaFileSetAssoc($id, $file_id, $set_id);	
                $MultimediaFileSetAssocs = new End_Models_MultimediaFileSetAssocs();						
                $MultimediaFileSetAssocs->_update($MultimediaFileSetAssoc);								
                $this->_helper->redirector('index');				
            } else 
            {
                $form->populate($formData);
            }
        } else 
        {
            $id = $this->_getParam('id', 0);
            if ($id > 0) 
            {
                $MultimediaFileSetAssocs = new End_Models_MultimediaFileSetAssocs();
                $form->populate(Utility_Converter::objectToArray($MultimediaFileSetAssocs->_find($id)));
            }
        }
    }
    
    public function indexAction()
    {
    	$modelMultimediaFileSetAssoc = new End_Models_MultimediaFileSetAssocs();
		$MultimediaFileSetAssocs = $modelMultimediaFileSetAssoc->fetchAll();
		$this->view->MultimediaFileSetAssocs = $MultimediaFileSetAssocs;
    }
    
}







